import { app1 as request } from '@/api/request';

// 图片管理
/**
 * @description 查询全部图片或视频
 * @method Get
 */
export function getPictureList<R, T>() {
  return request.Get<R, T>('/app1-picturemanagement/Picturelist');
}

/**
 * @description 批量删除图片或视频
 * @method Delete
 */
export function picturedeleteids<R, T>(id: number[]) {
  return request.Delete<R, T>('/app1-picturemanagement/picturedeleteids', id, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}
export function Picturesearch<R, T>(key: string) {
  return request.Get<R, T>(`/app1-picturemanagement/getPicByKey/${key}`, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * @description 编辑图片或视频
 * @method Put
 */
export function updatepicture<R, T>(change: any) {
  return request.Put<R, T>('/app1-picturemanagement/updatepicture', change, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * @description 上传图片或视频
 * @method Post
 */
export function uploadImgFile<R, T>(file: any) {
  return request.Post<R, T>('/app1-picturemanagement/uploadfile', file, {
    headers: {
      'Content-Type': 'multipart/form-data',
    },
  });
}

/**
 * @description 新增图片数据
 * @method Post
 */
export function insertPicture<R, T>(data: any) {
  return request.Post<R, T>('/app1-picturemanagement/insertpicture', data, {
    headers: {
      'Content-Type': 'application/json',
    },

  });
}

/**
 * @description 用户点击下载
 * @method Post
 */
export function clickToDownload<R, T>(pictureid: number, name: string) {
  const tokenName = {
    tokenName: name,
  };
  return request.Post<R, T>(`/app1-picturemanagement/insertuserpicture/${pictureid}`, tokenName, {
    headers: {
      'Content-Type': 'application/json',
    },
    responseType: 'blob',
  });
}

/**
 * @description 查询某个用户总共下载次数
 * @method Get
 */
export function getUserAllDownload<R, T>(name: string) {
  return request.Get<R, T>('/app1-picturemanagement/useralldownload', {
    params: { name },
  });
}

/**
 * @description 查询所有用户的图片记录
 * @method Get
 */
export function getImgInfoToUser<R, T>() {
  return request.Get<R, T>('/app1-picturemanagement/Pictureuserlist');
}

/**
 * @description 更新用户图片下载信息
 * @method Put
 */
export function updateImgUser<R, T>(item: any) {
  return request.Put<R, T>('/app1-picturemanagement/Pictureuserupdate', item, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * @description 根据关键字搜索图片
 * @method Get
 */
export function searchpicture<R, T>(keyWord: string) {
  return request.Get<R, T>(`/app1-picturemanagement/searchpicture/${keyWord}`, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * @description 根据事件类型查询图片
 * @method Get
 */
export function getImgByEvent<R, T>(event: string) {
  return request.Get<R, T>(`/app1-picturemanagement/searchByEvent`, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    params: { event },
  });
}

/**
 * @description 根据事件类型分页查询图片
 * @method Post
 */
export function getImgByEventPage<R, T>(event: any, currentPage: number, pageSize: number) {
  const data = { currentPage, pageSize };
  return request.Post<R, T>(`/app1-picturemanagement/searchByEventPage`, data, {
    headers: {
      'Content-Type': 'application/json',
    },
    params: { event },
  });
}

/**
 * @description 创建图片文件夹
 * @method Post
 */
export function createEvent<R, T>(name: string) {
  const data = { folderName: name };
  return request.Post<R, T>(`/app1-picturemanagement/create`, data, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * @description 修改图片文件夹
 * @method Put
 */
export function updateEvent<R, T>(id: number, folderName: string) {
  const data = { id, folderName };
  return request.Put<R, T>('/app1-picturemanagement/update', data, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}

/**
 * @description 查询所有文件夹
 * @method Get
 */
export function getEvent<R, T>() {
  return request.Get<R, T>('/app1-picturemanagement/listAll', {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * @description 删除图片文件夹
 * @method Delete
 */
export function deleteEvent<R, T>(id: number) {
  return request.Delete<R, T>(`/app1-picturemanagement/delete/${id}`, {
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });
}

/**
 * @description 查询所有图片（分页）
 * @method Post
 */
export function getAllPicturesPage<R, T>(currentPage: number, pageSize: number) {
  const data = { currentPage, pageSize };
  return request.Post<R, T>(`/app1-picturemanagement/getAllPicturesPage`, data, {
    headers: {
      'Content-Type': 'application/json',
    },
  });
}
